function findDiagonalOrderJs(mat) {
  let m = mat.length
  let n = mat[0].length
  const res = new Array(m * n).fill(0)
  let pos = 0
  for (let i = 0; i < m + n - 1; i++) {
    if (i % 2 === 1) {
      let x = i < n ? 0 : i - n + 1
      let y = i < n ? i : n - 1
      while (x < m && y >= 0) {
        console.log(pos, x, y);
        res[pos] = mat[x][y]
        pos++;
        x++;
        y--;
      }
    } else {
      let x = i < m ? i : m - 1;
      let y = i < m ? 0 : i - m + 1;
      while (x >= 0 && y < n) {
        res[pos] = mat[x][y];
        pos++;
        x--;
        y++;
      }
    }
  }
  console.log(res);
  return res
}

findDiagonalOrderJs([[1, 2, 3], [4, 5, 6], [7, 8, 9]])